package com.jwgf.protocolstack;

import android.os.Handler;

public abstract class CommandFeeder {

	protected ProtocolStack ps;
	
	private long pollingInterval = 3000; 
	public void setPollingInterval(long pollingInterval) {
		this.pollingInterval = pollingInterval;
	}

	private Handler handler = new Handler();
	private Runnable initRun = new Runnable() {

		@Override
		public void run() {
			feedInitCommand();
		}
	};

	private Runnable pollingRun = new Runnable() {

		@Override
		public void run() {
			feedPollingCommand();
			handler.postDelayed(pollingRun, pollingInterval);
		}
	};

	public CommandFeeder(ProtocolStack stack) {
		super();
		ps = stack;
	}

	public void start() {
		handler.post(initRun);
		handler.post(pollingRun);
	}

	protected abstract void feedInitCommand();

	protected abstract void feedPollingCommand();

}
